package netty01;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * 初始化channel,
 */
public class HelloServerInitializer extends ChannelInitializer<SocketChannel> {


    @Override
    protected void initChannel(SocketChannel channel) throws Exception {

        //获取pipeline
        ChannelPipeline pipeline = channel.pipeline();
        //添加拦截器，处理http请求、响应编码
        pipeline.addLast("HttpServerCodec", new HttpServerCodec());
        //自定义拦截器，返回 "hello netty" 消息
        pipeline.addLast("diyHandler", new DiyHandler());

    }
}
